<template>
    <div class="layout-list" :class="{ 'is-mobile': $isMobile }">
        <div class="layout-header">
            <div class="title">{{ title }}</div>
        </div>
        <div class="content">
            <div class="content-left">
                <div class="left-item" v-for="item in list" :class="{
                    'active-item': item.id === activeId,
                }" :key="item.id" @click="handleActiveMenu(item)">
                    <div class="menu-name">
                        {{ item.name }}
                    </div>
                </div>
            </div>
            <div class="content-right">
                <slot />
            </div>
        </div>
    </div>
</template>
  
<script>
export default {
    props: ['title', "list"],

    data() {
        return {
            activeId: "",
        };
    },

    mounted() {
        this.init();
    },

    methods: {
        init() {
            const route = this.list.find((item) => {
                return this.$route.fullPath.indexOf(item.id) > -1;
            });
            if (route) {
                this.activeId = route.id;
            } 
        },

        handleActiveMenu(item) {
            if (this.activeId === item.id) return;
            this.activeId = item.id;
            this.$router.push({
                name:  item.id,
            });
        },
    },

    watch: {},
};
</script>
  
<style lang="less" scoped>
.layout-list {
    background: #fff;
    height: 100%;
    min-height: inherit;
    display: flex;
    flex-direction: column;
}

.layout-header {
    border-bottom: 1px solid #efefef;
    width: 100%;

    .title {
        padding-left: 30px;
        height: 58px;
        font-family: PingFangSC, PingFang SC;
        font-weight: 600;
        font-size: 22px;
        color: #333333;
        text-align: left;
        font-style: normal;
        align-items: center;
        width: 250px;
        display: flex;
        user-select: none;
    }
}

.content {
    display: flex;
    flex-direction: row;
    width: 100%;
    flex: 1;

    .content-left {
        width: 220px;

        .left-item {
            width: calc(100% - 11px);
            box-sizing: border-box;
            line-height: 22px;
            padding: 14px 20px;
            margin-left: 10px;
            border-bottom: 1px solid #efefef;
            align-items: center;
            display: flex;
            cursor: pointer;
            flex-direction: column;
            border-right: 5px solid transparent;

            &:hover {
                color: #3560ab;
                background: #f2f7ff;
            }

            .menu-name {
                width: 100%;
            }

            &.active-item {
                color: #3560ab;
                border-right: 5px solid #3560ab;
                background: #f2f7ff;

            }
        }
    }
}

.content-right {
    flex: 1;
    border-left: 1px solid #efefef;
    overflow: hidden;
    min-height: 100%;
}

.layout-list.is-mobile {

    .layout-header {
        margin-bottom: 10px;

        .title {
            height: fit-content;
            padding: 10px;
        }
    }
    .content {
        display: flex;
        flex-direction: column;

        .content-left {
            display: flex;
            flex-wrap: wrap;
            flex-direction: row;
            width: 100%;
        }

        .left-item {
            width: fit-content;
            display: inline-flex;
            padding: 10px;
            border: none;

            &.active-item {
                border-right: 0;
            }
        }
    }
}
</style>